package com.wlr.study.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class LeetCode383 {
    public static boolean canConstruct(String ransomNote, String magazine) {
        HashMap<Character, Integer> ransomNoteMap = new HashMap<>();
        HashMap<Character, Integer> magazineMap = new HashMap<>();
        for (int i = 0; i < ransomNote.length(); i++) {
            ransomNoteMap.put(ransomNote.charAt(i), ransomNoteMap.getOrDefault(ransomNote.charAt(i),0) + 1);
        }
        for (int i = 0; i < magazine.length(); i++) {
            magazineMap.put(magazine.charAt(i), magazineMap.getOrDefault(magazine.charAt(i),0) + 1);
        }
        Set<Map.Entry<Character, Integer>> entries = ransomNoteMap.entrySet();
        for (Map.Entry<Character, Integer> entry: entries) {
            if (magazineMap.get(entry.getKey())==null||magazineMap.get(entry.getKey())<entry.getValue()){
                return false;
            }
        }
        return true;
    }


    public static void numAdd(Integer num){
        num=num+1;
        System.out.println(num);
    }

    public static void main(String[] args) {
        Integer a =1;
        LeetCode383.numAdd(a);
        System.out.println(a);
        System.out.println(LeetCode383.canConstruct("a", "b"));
    }
}
